package com.longrise.android.byjk.plugins.tabfirst.revision.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.longrise.common.base.BaseFragment;
import com.longrise.android.byjk.plugins.tabfirst.revision.fragment.HealthyFragment;
import com.longrise.android.byjk.plugins.tabfirst.revision.fragment.InsNewTopFragment;
import com.longrise.android.byjk.plugins.tabfirst.revision.fragment.NewComFragment;
import com.longrise.android.byjk.plugins.tabfirst.revision.fragment.RecComFragment;

/**
 * Created by sujizhong on 2017/2/24.
 * 问答 资讯 适配器
 */

public class HomeFragAdapter extends FragmentPagerAdapter {

    private int mType = 0;

    /**
     * 资讯
     */
    public static final int mInsFrag = 0;
    /**
     * 问答
     */
    public static final int mConFrag = 1;

    private final int mCount = 1;

    public InsNewTopFragment mInsNewTopFragment;
    public HealthyFragment mHealthyFragment;

    public NewComFragment mNewComFragment;
    public RecComFragment mRecComFragment;

    private String title = "保险动态";

    public HomeFragAdapter(FragmentManager fm, int type) {
        super(fm);
        this.mType = type;
    }

    @Override
    public Fragment getItem(int position) {
        return getFragment(position);
    }

    @Override
    public int getCount() {
        return mCount;
    }

//    @Override
//    public CharSequence getPageTitle(int position) {
//        return getTitle(position);
//    }

//    private String getTitle(int position) {
//
//        return title;
////        if (position == 0) {
////            return mType == mInsFrag ? "保险动态" : "最新提问";
////        } else {
////            return mType == mInsFrag ? "健康养生" : "推荐问答";
////        }
//    }

    private BaseFragment getFragment(int position) {

        return createInsTopFragment();
//        if (position == 0) {
//            return mType == mInsFrag ? createInsTopFragment() : createNewComFragment();
//        } else {
//            return mType == mInsFrag ? createHealthyFragment() : createReComFragment();
//        }
    }

    /**保宝头条*/
    private BaseFragment createInsTopFragment() {
        if (mInsNewTopFragment == null) {
            mInsNewTopFragment = new InsNewTopFragment();
        }
        return mInsNewTopFragment;
    }

    /**健康养生*/
    private BaseFragment createHealthyFragment() {
        if (mHealthyFragment == null) {
            mHealthyFragment = new HealthyFragment();
        }
        return mHealthyFragment;
    }

    /**最新提问*/
    private BaseFragment createNewComFragment() {
        if (mNewComFragment == null) {
            mNewComFragment = new NewComFragment();
        }
        return mNewComFragment;
    }

    /**推荐回答*/
    private BaseFragment createReComFragment() {
        if (mRecComFragment == null) {
            mRecComFragment = new RecComFragment();
        }
        return mRecComFragment;
    }

  public void release() {

    }
}
